package com.gun3y.entity.media;

import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.gun3y.exception.ExceptionCode;
import com.gun3y.exception.SWException;

public enum PropertyType {
    name {
	@Override
	public List<Data> getData(Movie movie) {
	    return Collections.emptyList();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {

	}
    },

    actor {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getActors();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setActors(datas);
	    }
	}
    },

    contentRating {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getContentRating();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setContentRating(datas);
	    }
	}
    },

    creator {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getCreators();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setCreators(datas);
	    }
	}
    },

    datePublished {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getDatePublished();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setDatePublished(datas);
	    }
	}
    },

    description {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getDescription();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setDescription(datas);
	    }
	}
    },

    director {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getDirectors();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setDirectors(datas);
	    }
	}
    },

    duration {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getDuration();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setDuration(datas);
	    }
	}
    },

    genre {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getGenre();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setGenre(datas);
	    }
	}
    },

    image {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getImage();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setImage(datas);
	    }
	}
    },

    keywords {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getKeyword();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setKeyword(datas);
	    }
	}
    },

    productionCompany {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getProductionCompany();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setProductionCompany(datas);
	    }
	}
    },

    provider {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getProvider();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setProvider(datas);
	    }
	}
    },

    rating {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getRating();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setRating(datas);
	    }
	}
    },

    url {
	@Override
	public List<Data> getData(Movie movie) {
	    if (movie == null)
		return Collections.emptyList();
	    return movie.getUrl();
	}

	@Override
	public void setData(Movie movie, List<Data> datas) {
	    if (movie != null) {
		movie.setUrl(datas);
	    }
	}
    };

    public static PropertyType getPropertyType(String str) {
	if (StringUtils.isBlank(str)) {
	    throw new SWException(ExceptionCode.InvalidInput);
	}

	return PropertyType.valueOf(str.substring(str.indexOf("#") + 1));
    }

    public abstract List<Data> getData(Movie movie);

    public abstract void setData(Movie movie, List<Data> datas);

}
